<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GNetworkAddress</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="index.html" title="GIO 参考手册">
<link rel="up" href="resolver.html" title="DNS resolution">
<link rel="prev" href="gio-GSocketConnectable.html" title="GSocketConnectable">
<link rel="next" href="gio-GNetworkService.html" title="GNetworkService">
<meta name="generator" content="GTK-Doc V1.17 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="gio-GSocketConnectable.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="resolver.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GIO 参考手册</th>
<td><a accesskey="n" href="gio-GNetworkService.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts">
<a href="#gio-GNetworkAddress.synopsis" class="shortcut">Top</a>
                   | 
                  <a href="#gio-GNetworkAddress.description" class="shortcut">Description</a>
</td></tr>
</table>
<div class="refentry">
<a name="gio-GNetworkAddress"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="gio-GNetworkAddress.top_of_page"></a>GNetworkAddress</span></h2>
<p>GNetworkAddress — A GSocketConnectable for resolving hostnames</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<a name="gio-GNetworkAddress.synopsis"></a><h2>Synopsis</h2>
<pre class="synopsis">
#include &lt;gio/gio.h&gt;

                    <a class="link" href="gio-GNetworkAddress.html#GNetworkAddress" title="GNetworkAddress">GNetworkAddress</a>;
<a class="link" href="gio-GSocketConnectable.html#GSocketConnectable" title="GSocketConnectable"><span class="returnvalue">GSocketConnectable</span></a> * <a class="link" href="gio-GNetworkAddress.html#g-network-address-new" title="g_network_address_new ()">g_network_address_new</a>              (<em class="parameter"><code>const <a href="../glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *hostname</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Basic-Types.html#guint16"><span class="type">guint16</span></a> port</code></em>);
const <a href="../glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> *       <a class="link" href="gio-GNetworkAddress.html#g-network-address-get-hostname" title="g_network_address_get_hostname ()">g_network_address_get_hostname</a>      (<em class="parameter"><code><a class="link" href="gio-GNetworkAddress.html#GNetworkAddress" title="GNetworkAddress"><span class="type">GNetworkAddress</span></a> *addr</code></em>);
<a href="../glib/glib-Basic-Types.html#guint16"><span class="returnvalue">guint16</span></a>             <a class="link" href="gio-GNetworkAddress.html#g-network-address-get-port" title="g_network_address_get_port ()">g_network_address_get_port</a>          (<em class="parameter"><code><a class="link" href="gio-GNetworkAddress.html#GNetworkAddress" title="GNetworkAddress"><span class="type">GNetworkAddress</span></a> *addr</code></em>);
const <a href="../glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> *       <a class="link" href="gio-GNetworkAddress.html#g-network-address-get-scheme" title="g_network_address_get_scheme ()">g_network_address_get_scheme</a>        (<em class="parameter"><code><a class="link" href="gio-GNetworkAddress.html#GNetworkAddress" title="GNetworkAddress"><span class="type">GNetworkAddress</span></a> *addr</code></em>);
<a class="link" href="gio-GSocketConnectable.html#GSocketConnectable" title="GSocketConnectable"><span class="returnvalue">GSocketConnectable</span></a> * <a class="link" href="gio-GNetworkAddress.html#g-network-address-parse" title="g_network_address_parse ()">g_network_address_parse</a>            (<em class="parameter"><code>const <a href="../glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *host_and_port</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Basic-Types.html#guint16"><span class="type">guint16</span></a> default_port</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);
<a class="link" href="gio-GSocketConnectable.html#GSocketConnectable" title="GSocketConnectable"><span class="returnvalue">GSocketConnectable</span></a> * <a class="link" href="gio-GNetworkAddress.html#g-network-address-parse-uri" title="g_network_address_parse_uri ()">g_network_address_parse_uri</a>        (<em class="parameter"><code>const <a href="../glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *uri</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Basic-Types.html#guint16"><span class="type">guint16</span></a> default_port</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);
</pre>
</div>
<div class="refsect1">
<a name="gio-GNetworkAddress.description"></a><h2>Description</h2>
<p>
<a class="link" href="gio-GNetworkAddress.html#GNetworkAddress" title="GNetworkAddress"><span class="type">GNetworkAddress</span></a> provides an easy way to resolve a hostname and
then attempt to connect to that host, handling the possibility of
multiple IP addresses and multiple address families.
</p>
<p>
See <a class="link" href="gio-GSocketConnectable.html#GSocketConnectable" title="GSocketConnectable"><span class="type">GSocketConnectable</span></a> for and example of using the connectable
interface.
</p>
</div>
<div class="refsect1">
<a name="gio-GNetworkAddress.details"></a><h2>Details</h2>
<div class="refsect2">
<a name="GNetworkAddress"></a><h3>GNetworkAddress</h3>
<pre class="programlisting">typedef struct {
  GObject parent_instance;
} GNetworkAddress;
</pre>
<p>
A <a class="link" href="gio-GSocketConnectable.html#GSocketConnectable" title="GSocketConnectable"><span class="type">GSocketConnectable</span></a> for resolving a hostname and connecting to
that host.
</p>
</div>
<hr>
<div class="refsect2">
<a name="g-network-address-new"></a><h3>g_network_address_new ()</h3>
<pre class="programlisting"><a class="link" href="gio-GSocketConnectable.html#GSocketConnectable" title="GSocketConnectable"><span class="returnvalue">GSocketConnectable</span></a> * g_network_address_new              (<em class="parameter"><code>const <a href="../glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *hostname</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Basic-Types.html#guint16"><span class="type">guint16</span></a> port</code></em>);</pre>
<p>
Creates a new <a class="link" href="gio-GSocketConnectable.html#GSocketConnectable" title="GSocketConnectable"><span class="type">GSocketConnectable</span></a> for connecting to the given
<em class="parameter"><code>hostname</code></em> and <em class="parameter"><code>port</code></em>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>hostname</code></em> :</span></p></td>
<td>the hostname</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>port</code></em> :</span></p></td>
<td>the port</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the new <a class="link" href="gio-GNetworkAddress.html#GNetworkAddress" title="GNetworkAddress"><span class="type">GNetworkAddress</span></a>. <span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.22</p>
</div>
<hr>
<div class="refsect2">
<a name="g-network-address-get-hostname"></a><h3>g_network_address_get_hostname ()</h3>
<pre class="programlisting">const <a href="../glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> *       g_network_address_get_hostname      (<em class="parameter"><code><a class="link" href="gio-GNetworkAddress.html#GNetworkAddress" title="GNetworkAddress"><span class="type">GNetworkAddress</span></a> *addr</code></em>);</pre>
<p>
Gets <em class="parameter"><code>addr</code></em>'s hostname. This might be either UTF-8 or ASCII-encoded,
depending on what <em class="parameter"><code>addr</code></em> was created with.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>addr</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GNetworkAddress.html#GNetworkAddress" title="GNetworkAddress"><span class="type">GNetworkAddress</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<em class="parameter"><code>addr</code></em>'s hostname</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.22</p>
</div>
<hr>
<div class="refsect2">
<a name="g-network-address-get-port"></a><h3>g_network_address_get_port ()</h3>
<pre class="programlisting"><a href="../glib/glib-Basic-Types.html#guint16"><span class="returnvalue">guint16</span></a>             g_network_address_get_port          (<em class="parameter"><code><a class="link" href="gio-GNetworkAddress.html#GNetworkAddress" title="GNetworkAddress"><span class="type">GNetworkAddress</span></a> *addr</code></em>);</pre>
<p>
Gets <em class="parameter"><code>addr</code></em>'s port number
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>addr</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GNetworkAddress.html#GNetworkAddress" title="GNetworkAddress"><span class="type">GNetworkAddress</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<em class="parameter"><code>addr</code></em>'s port (which may be 0)</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.22</p>
</div>
<hr>
<div class="refsect2">
<a name="g-network-address-get-scheme"></a><h3>g_network_address_get_scheme ()</h3>
<pre class="programlisting">const <a href="../glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> *       g_network_address_get_scheme        (<em class="parameter"><code><a class="link" href="gio-GNetworkAddress.html#GNetworkAddress" title="GNetworkAddress"><span class="type">GNetworkAddress</span></a> *addr</code></em>);</pre>
<p>
Gets <em class="parameter"><code>addr</code></em>'s scheme
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>addr</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GNetworkAddress.html#GNetworkAddress" title="GNetworkAddress"><span class="type">GNetworkAddress</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<em class="parameter"><code>addr</code></em>'s scheme (<a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> if not built from URI)</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.26</p>
</div>
<hr>
<div class="refsect2">
<a name="g-network-address-parse"></a><h3>g_network_address_parse ()</h3>
<pre class="programlisting"><a class="link" href="gio-GSocketConnectable.html#GSocketConnectable" title="GSocketConnectable"><span class="returnvalue">GSocketConnectable</span></a> * g_network_address_parse            (<em class="parameter"><code>const <a href="../glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *host_and_port</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Basic-Types.html#guint16"><span class="type">guint16</span></a> default_port</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>
Creates a new <a class="link" href="gio-GSocketConnectable.html#GSocketConnectable" title="GSocketConnectable"><span class="type">GSocketConnectable</span></a> for connecting to the given
<em class="parameter"><code>hostname</code></em> and <em class="parameter"><code>port</code></em>. May fail and return <a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> in case
parsing <em class="parameter"><code>host_and_port</code></em> fails.
</p>
<p>
<em class="parameter"><code>host_and_port</code></em> may be in any of a number of recognised formats; an IPv6
address, an IPv4 address, or a domain name (in which case a DNS
lookup is performed). Quoting with [] is supported for all address
types. A port override may be specified in the usual way with a
colon. Ports may be given as decimal numbers or symbolic names (in
which case an /etc/services lookup is performed).
</p>
<p>
If no port is specified in <em class="parameter"><code>host_and_port</code></em> then <em class="parameter"><code>default_port</code></em> will be
used as the port number to connect to.
</p>
<p>
In general, <em class="parameter"><code>host_and_port</code></em> is expected to be provided by the user
(allowing them to give the hostname, and a port overide if necessary)
and <em class="parameter"><code>default_port</code></em> is expected to be provided by the application.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>host_and_port</code></em> :</span></p></td>
<td>the hostname and optionally a port</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>default_port</code></em> :</span></p></td>
<td>the default port if not in <em class="parameter"><code>host_and_port</code></em>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
<td>a pointer to a <a href="../glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a>, or <a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the new <a class="link" href="gio-GNetworkAddress.html#GNetworkAddress" title="GNetworkAddress"><span class="type">GNetworkAddress</span></a>, or <a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> on error. <span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.22</p>
</div>
<hr>
<div class="refsect2">
<a name="g-network-address-parse-uri"></a><h3>g_network_address_parse_uri ()</h3>
<pre class="programlisting"><a class="link" href="gio-GSocketConnectable.html#GSocketConnectable" title="GSocketConnectable"><span class="returnvalue">GSocketConnectable</span></a> * g_network_address_parse_uri        (<em class="parameter"><code>const <a href="../glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *uri</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Basic-Types.html#guint16"><span class="type">guint16</span></a> default_port</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>
Creates a new <a class="link" href="gio-GSocketConnectable.html#GSocketConnectable" title="GSocketConnectable"><span class="type">GSocketConnectable</span></a> for connecting to the given
<em class="parameter"><code>uri</code></em>. May fail and return <a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> in case parsing <em class="parameter"><code>uri</code></em> fails.
</p>
<p>
Using this rather than <a class="link" href="gio-GNetworkAddress.html#g-network-address-new" title="g_network_address_new ()"><code class="function">g_network_address_new()</code></a> or
<code class="function">g_network_address_parse_host()</code> allows <a class="link" href="gio-GSocketClient.html#GSocketClient" title="GSocketClient"><span class="type">GSocketClient</span></a> to determine
when to use application-specific proxy protocols.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>uri</code></em> :</span></p></td>
<td>the hostname and optionally a port</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>default_port</code></em> :</span></p></td>
<td>The default port if none is found in the URI</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
<td>a pointer to a <a href="../glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a>, or <a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the new <a class="link" href="gio-GNetworkAddress.html#GNetworkAddress" title="GNetworkAddress"><span class="type">GNetworkAddress</span></a>, or <a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> on error. <span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.26</p>
</div>
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.17</div>
</body>
</html>